<div class="box">
    <div class="heading">
        <h1><img alt="" src="<?php echo base_url('assets/admin/images/review.png'); ?>"> Alan Message</h1>
		<div class="buttons">
            <ul id="add_entry_btn">
                
                <li>
                    <a class="button delete" href="#"><span>Delete</span></a>
                </li>
            </ul>
        </div>  
    </div>
    <div class="content">
		<?php echo form_open(); ?>
        <div class="filter">
            <div class="left">
                <div><label>Admin Status:</label></div>
				<?php echo form_dropdown('filter[approve]', array(''=>'', 'Processing'=>'Processing', 'Approved'=>'Approved','Denied'=>'Denied'), set_filter('alan_messagebox', 'approve')); ?></td>
             </div>
            <div class="left">
                <div><label>Open Status:</label></div> 
                <?php echo form_dropdown('filter[openstatus]', array(''=>'', '1'=>'Read', '0'=>'Unread'), set_filter('alan_messagebox', 'openstatus')); ?></td>
            </div>
            <div class="left filter_buttons">
                <button name="submit" class="button" type="submit"><span>Filter</span></button>
                <button name="clear_filter" value="1" class="button" type="submit"><span>Clear</span></button>
            </div>
            <div class="clear"></div>
        </div>
        <?php echo form_close(); ?>

		<?php echo form_open(null, 'id="form"'); ?>
        <table id="entries_table" class="list">
            <thead>
                <tr>
                    <th width="1" class="center"><input type="checkbox" onClick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></th>
                    <th>From Member Name</th>
					<th>To Member Name</th>
					
					<th>Message</th>
					<th>Date</th>
					<th>Admin Status</th>
					<th>Open Status</th>
                    <th class="right">Action</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($inbox){?>
                    <?php foreach($inbox as $message){ ?>
                    <tr>
                        <td class="center"><input type="checkbox" value="<?php echo $message['id'] ?>" name="selected[]"/></td>
						<td><?php echo $message['fromname'];?></td>
						<td><?php echo $message['toname']; ?></td>
						
                        <td><?php echo $message['message']; ?></td>
						<td><?php echo $message['date_added']; ?></td>
						<td>
							<input type="hidden" value="<?php echo $message['id'] ?>" name="messageid"/>
							<?php echo form_dropdown('approve', array('Processing'=>'Processing', 'Approved'=>'Approved','Denied'=>'Denied'),set_value('approve',!empty($message['approve']) ? $message['approve'] : '') )?>
						</td>
						<td>
						<?php echo ($message['openstatus']==1?'Read':'Unread'); ?>
						</td>
						<td class="right">[ <?php echo anchor(ADMIN_PATH . "/alan/deletmessage/" .$this->uri->segment(4).'/'. $message['id'], 'Delete', 'onclick="return confirm(\'Delete cannot be undone! Are you sure you want to do this?\')"'); ?> ]</td>
                    </tr>
                    <?php } ?>
				<?php }else { ?>
                    <tr class="center"><td colspan="8">No results found.</td></tr>
                <?php } ?>
				
            </tbody>
        </table>
		<div id="paging">
				<?php if($pagination): ?>
					
					<div class="pagination">
						<div class="links"><?php echo $pagination; ?></div>
					</div>
				<?php endif; ?>
			</div>
        <?php echo form_close(); ?>
        
    </div>
</div>
<script>
$(function(){
	$('select').bind('change', function() {
		var id=$(this).prev().val();
		$.ajax({
			url: '<?php echo base_url('ajax/aprovemessage')?>',
			
			type :'POST',
			data:{messageid:id,approve:this.value},
			beforeSend: function() {
				$('select[name=\'approve\']').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
			},		
			complete: function() {
				$('.wait').remove();
			},			
			success: function(data) {
				alert(data);
			}
		});
	});
});
 // Delete
        $('.delete').click( function() {
            if (confirm('Delete cannot be undone! Are you sure you want to do this?'))
            {
                $('#form').attr('action', '<?php echo site_url(ADMIN_PATH . '/alan/deletmessage/'.$this->uri->segment(4)); ?>').submit()
            }
            else
            {
                return false;
            }
        });
</script>
